<template>
  <div class="header">
    <div class="left">
      <img src="../assets/logo.png" alt="定时红包" class="logo">
      <p class="text">天天兼职后台管理</p>
    </div>
    <div class="right">
      <p class="user">用户名：<span class="iphone">{{userName}}</span> </p>

      <p class="login"><el-button type="danger" size="mini" icon="el-icon-error" circle @click="loginOut"></el-button></p>
    </div>
  </div>
</template>
<script>
import {getCookie,setCookie} from './until/index'

export default {
  data () {
    return {
      activeIndex: '1',
      userName:''
    }
  },
  methods: {
    loginOut(command){
      
      this.$confirm('此操作将退出登录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {

          this.$message({
            type: 'success',
            message: '退出成功',
            onClose:()=>{
              setCookie('token','',-1)
              setCookie('userid','',-1)
              window.location.href='/'
            }
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出'
          });          
        });
    
    }
  },
  created () {

    this.$ajax.get('admGetUserInfo.ashx?uid='+getCookie('userid')+'&token='+getCookie('token'))
        .then(res=>{
          if(res.data.code == 200){
            var data = res.data.data
            this.userName = data.nickName
          }else{

            this.$message.error(res.data.msg+'请退出后重新登录');
          }
        })
        .catch(error=>{
          this.$message.error(error)
        })
  }
}
</script>
<style scoped>
.header{
  width: 100%;
  height: 100%;
}
.logo{
  float: left;
  width: 40px;
  height: 40px;
  display: block;
  margin: 14px 0 0 20px
}
.text{
  width: 160px;
  color: #fff;
  font-size: 14px;
  line-height: 55px;
  overflow: hidden;
}
.left{
  float: left;
}
.right{
  float: right;
}
.right p{
  display: inline;
  line-height: 68px;
  font-size: 14px;
}
.right p.user{
  margin-right: 15px;
}
.right p.login{
  cursor: pointer;
}
.el-dropdown{
  color: #fff;
  cursor: pointer;
}
</style>
